<tagLib name="html" />
<script type="text/javascript">
	function add_contact_record() {
		$("#form_lianxijilu :input :not(:button) :not('select')").each(function() {
			$(this).val("");
		});
		$("#form_lianxijilu :text").each(function() {
			$(this).val("");
		});
		$("#form_lianxijilu select").each(function() {
			$(this).find('option:first').attr('selected', 'selected');
		});
		$(".contact_record_sub_left_menu tr.active").removeClass("active");
		$("#contact_record_opmode").val("add");
	}

	function save_contact_record() {
		if(check_form("form_lianxijilu")){
      sendForm("form_lianxijilu", "{:U('contact_record/save')}",window.location.href);
		}		
	}

  function destroy_contact_record() {
    var id = $(".contact_record_sub_left_menu  tr.active").attr('id');
    if(id==undefined){
      alert('请先选择联系记录');
      return false;
    }
    sendAjax("{:U('contact_record/del')}", "id=" + id, function(data) {
        if(data['status']=='1'){
          alert(data['info']);
        }else{
          alert('未成功！'); 
        };
       location.reload();
    });
  }

	function showdata(result) {
		for (var s in result.data) {
      //alert(s);
			set_val(s,result.data[s]);
		}
    $("#contact_result_id_"+result.data['contact_result_id']).click(); 
    //if(result.data['contact_result_id'] == 1){
    //}
		//$("#dept_name").val($("#dept_list option[value='" + $("#dept_id").val() + "']").text());
		//img_url = "{:C('SAVE_PATH')}" + $("#pic").val();
		//$("#emp_pic").attr("src", img_url.split(";")[0]);
		$("#save_name").val("");
		$("#opmode").val("edit");
	}

	$(document).ready(function(){		
	//	$(".input-date").datepicker();
		$(".contact_record_sub_left_menu  tr").click(function() {
			$(".contact_record_sub_left_menu  tr.active").removeClass("active");
      $('#contact_record_opmode').val('edit');
      $('#contact_record_id').val($(this).attr('id'));
			$(this).attr("class","active");
      //alert($(this).attr('id'));
			sendAjax("{:U('contact_record/read')}", "id=" + $(this).attr("id"), function(data) {
        //alert(data);
				showdata(data);
			});
			return false;
		})
	});

</script>
<div class="admin" >
	<form method="post" action="" id="form_search" name="form_search">
		<div class="row-fluid title">
      <a href="javascript:void($('#lianxijilu').toggle())">
        <span>联系记录管理</span>
      </a>
		</div>
	</form>
  <div id="lianxijilu" style="display:none;">
	<div class="row-fluid operate" >
		<div class="right">
			<a onclick="add_contact_record()"  class="btn">新增</a>
			<a onclick="save_contact_record()"  class="btn">保存</a>
			<a onclick="destroy_contact_record()"  class="btn">删除</a>
		</div>
	</div>
	<div class="row-fluid">
		<div class="span4 contact_record_sub_left_menu ">
			<table class="table table-bordered">
				<tr>
					<th>联系时间</th>
					<th>联系人</th>
					<th>联系结果</th>
				</tr>
        <?php// $lianxijilu = $vo['contact_record']  ?>
        <?php// print_r($vo); ?>
        <?php// print_r($lianxijilu); ?>
				<volist name="contact_record_list" id="lianxijilu">
					<tr id="{$lianxijilu.id}">
						<td>{$lianxijilu.created_at}</td>
            <td><?php echo $lianxijilu['contact_person']['name'] ?></td>
            <td><?php echo $lianxijilu['contact_result_id'] == 1 ? '有效' : '无效' ?></td>
					</tr>
				</volist>
			</table>
		</div>
		<div class="span8">
			<form id="form_lianxijilu" name="form_lianxijilu" method="post" action="">
				<input type="hidden" id="save_name" name="save_name">
				<input type="hidden" name="id" id="contact_record_id">
				<input type="hidden" name="pid" id="contact_record_pid" value="">
        <input type="hidden" name="mini_client_id" id="contact_record_mini_client_id" value="{$vo.id}">
				<input type="hidden" name="pic" id="contact_record_pic" >
				<input type="hidden" name="ajax" id="contact_record_ajax" value="1">
				<input type="hidden" name="opmode" id="contact_record_opmode" value="">
				<!--<input type="hidden" name="created_user_id" id="contact_record_created_user_id" value="">-->
				<!--<html:select id="dept_list" name="dept_list"  options="dept_list" style="dis"/>-->
				<table class="table table-bordered" >
					<tr>
						<th>联系人*</th>
            <?php 
            foreach ($lianxiren_list as $lxr ) {
              $lianxiren_select_list[$lxr['id']] = $lxr['name'];
            }
           // print_r($lianxiren_select_list);
            //print_r($contact_way_list);
            ?>
						<td>
              <html:select id="contact_person_id" name="contact_person_id"  options="lianxiren_select_list" style="input-small"/>
              <!--<input type="text" id="name" name="name" class="input-small" check="require" msg="请输入姓名">-->
            </td>
						<th>联系方式</th>
						<td>
              <html:select id="contact_way_id" name="contact_way_id"  options="contact_way_list" style="input-small"/>
						</td>
					</tr>
					<tr>
						<th>联系结果*</th>
						<td colspan=3>
              <span class="span6">
                有效的联系：<input id="contact_result_id_1" checked="checked" type="radio" value="1" onclick="$('.youxiao').show();$('.wuxiao').hide();" name="contact_result_id">
              </span>
              <span class="span6">
                无效的联系:<input id="contact_result_id_0" type="radio" value="0" onclick="$('.youxiao').hide();$('.wuxiao').show();" name="contact_result_id">
              </span>
            </td>
					</tr>
					<tr class='youxiao' style=";">
						<th>介绍产品</th>
						<td colspan=3>
              <input type="text" id="introduce_product" name="introduce_product" class="span12">
						</td>
					</tr>
					<tr class='youxiao' style=";">
						<th>介绍服务</th>
						<td colspan=3>
              <input type="text" id="introduce_server" name="introduce_server" class="span12">
						</td>
					</tr>
					<tr class="youxiao" style=";">
						<th>兴趣点</th>
						<td colspan=3>
              <input type="text" id="interest_point" name="interest_point" class="span12">
						</td>
					</tr>
					<tr class='youxiao' style=";">
						<th>异议点</th>
						<td colspan=3>
              <input type="text" id="dissent_point" name="dissent_point" class="span12">
						</td>
					</tr>
					<tr class='youxiao' style=";">
						<th>沟通记录</th>
						<td colspan=3>
              <input type="text" id="description" name="description" class="span12">
						</td>
					</tr>
					<tr class='youxiao' style=";">
						<th>跟进思路</th>
						<td colspan=3>
              <input type="text" id="follow_ideas" name="follow_ideas" class="span12">
						</td>
					</tr>
					<tr class="wuxiao" style="display:none;">
						<th>联系备注</th>
						<td colspan="3">
              <input type="text" name="invalid_contact_description" id="invalid_contact_description" class="span12">
						</td>
						</td>
					</tr>
				</table>
			</form>
		</div>
    <div id="contact_record_page">
    </div>
	</div>
</div>
</div>
